#include "netdisk.h"

int main(int argc,char** argv)
{
    if(argc!=3)
    {
        printf("./ IP PORT\n");
        return -1;
    }
    int socket_fd;
    socket_fd=get_tcp_socket(argv[1],argv[2]);//初始化得到内核中的socket描述符
    int new_fd;
    struct sockaddr_in client_addr;//对客户端进行初始化
    bzero(&client_addr,sizeof(client_addr));
    socklen_t addr_len=sizeof(client_addr);
    while(1)
    {
        new_fd=accept(socket_fd,(struct sockaddr *)&client_addr,&addr_len);//连接，产生用于通信的new_fd
        ERROR_CHECK(new_fd,-1,"accept")
        pchild_use p=(pchild_use)malloc(sizeof(child_use));
        p->fd=new_fd;
        if(!fork())
        {
            child_func(p);
            exit(1);
        }
        free(p);
        bzero(p,sizeof(child_use));
    }
    return 0;
}